{{- define "openstack_cloud_config" }}
{{- $internal := .Values.cloudProviderOpenstack.internal }}
[Global]
auth-url = {{ $internal.connection.authURL | quote }}
domain-name = {{ $internal.connection.domainName | quote }}
{{- if hasKey $internal.connection "tenantName" }}
tenant-name = {{ $internal.connection.tenantName | quote }}
{{- end }}
{{- if hasKey $internal.connection "tenantID" }}
tenant-id = {{ $internal.connection.tenantID | quote }}
{{- end }}
username = {{ $internal.connection.username | quote }}
password = {{ $internal.connection.password | quote }}
region = {{ $internal.connection.region | quote }}
  {{- if $internal.connection.caCert }}
ca-file = /etc/config/ca.crt
  {{- end }}
[Networking]
  {{- if hasKey $internal "externalNetworkNames" }}
    {{- range $internal.externalNetworkNames }}
public-network-name = {{ . | quote }}
    {{- end }}
  {{- end }}
  {{- if hasKey $internal "internalNetworkNames" }}
    {{- range $internal.internalNetworkNames }}
internal-network-name = {{ . | quote }}
    {{- end }}
  {{- end }}
ipv6-support-disabled = true
[LoadBalancer]
create-monitor = "true"
monitor-delay = "2s"
monitor-timeout = "1s"
  {{- if hasKey $internal "loadBalancer" }}
    {{- if hasKey .Values.cloudProviderOpenstack.internal.loadBalancer "subnetID" }}
subnet-id = {{ .Values.cloudProviderOpenstack.internal.loadBalancer.subnetID | quote }}
    {{- end }}
    {{- if hasKey .Values.cloudProviderOpenstack.internal.loadBalancer "floatingNetworkID" }}
floating-network-id = {{ .Values.cloudProviderOpenstack.internal.loadBalancer.floatingNetworkID | quote }}
    {{- end }}
  {{- end }}
enable-ingress-hostname = true
[BlockStorage]
ignore-volume-microversion = {{ .Values.cloudProviderOpenstack.ignoreVolumeMicroversion }}
rescan-on-resize = true
{{- end }}
---
apiVersion: v1
kind: Secret
metadata:
  name: cloud-controller-manager
  namespace: d8-cloud-provider-openstack
  {{- include "helm_lib_module_labels" (list . (dict "app" "cloud-controller-manager")) | nindent 2 }}
type: Opaque
data:
  cloud-config: {{ include "openstack_cloud_config" . | b64enc | quote }}
{{- if hasKey .Values.cloudProviderOpenstack.internal.connection "caCert" }}
  ca.crt: {{ .Values.cloudProviderOpenstack.internal.connection.caCert | b64enc | quote }}
{{- end }}
